#!/bin/bash
#mha-manager
yum install -y perl-Time-HiRes perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager \
perl-ExtUtils-CBuilder perl-Module-Build
tar zxvf mha4mysql-manager-0.58.tar.gz
cd  mha4mysql-manager-0.58
perl Makefile.PL
make
make install
cd ..

#install cpanm
wget -c https://cpan.metacpan.org/authors/id/M/MI/MIYAGAWA/App-cpanminus-1.7044.tar.gz
tar zxvf App-cpanminus-1.7044.tar.gz
cd App-cpanminus-1.7044
perl Makefile.PL
make
make install
cd ..
#install Socket
cpanm --mirror http://mirrors.aliyun.com/CPAN/ --mirror-only IO::Socket::INET6
cpanm --mirror http://mirrors.aliyun.com/CPAN/ --mirror-only ExtUtils::Constant
cpanm --mirror http://mirrors.aliyun.com/CPAN/ --mirror-only YAML
cpanm --mirror http://mirrors.aliyun.com/CPAN/ --mirror-only Socket

rm -rf /etc/mha/
mkdir -p /etc/mha/{conf,log,scripts}
cp -r conf/app1.cnf /etc/mha/conf/
cp -r scripts/* /etc/mha/scripts/
cp mha4mysql-manager-0.58/samples/scripts/send_report /etc/mha/scripts/

#check
##masterha_check_status --conf=/etc/mha/conf/app1.cnf
##masterha_check_ssh --conf=/etc/mha/conf/app1.cnf
##masterha_check_repl --conf=/etc/mha/conf/app1.cnf
#run
##nohup masterha_manager --conf=/etc/mha/conf/app1.cnf --ignore_last_failover &
#check status of RUNNING


